

using System;

namespace NodeBasedSkillEditor.Model.Node.RT
{
    public class Node_EnumToInteger_RT : RT_Node
    {
        public RT_SingleValuePort EnumIn_RT;

        public RT_SingleValuePort IntegerOut_RT;

        public Node_EnumToInteger_RT(Node_EnumToInteger sourceData, RT_DAG parentDag) : base(sourceData, parentDag)
        {
            EnumIn_RT = new RT_SingleValuePort(EPortIOType.Input, sourceData.EnumIn, this);

            IntegerOut_RT = new RT_SingleValuePort(EPortIOType.Output, sourceData.IntegerOut, this);
            IntegerOut_RT.OnGetValue = GetIntegerOut;
        }

        public AValue GetIntegerOut(DAG_Executor executor)
        {
            var enumValue = EnumIn_RT.SourceValue as Value_Enum;
            if (enumValue.Value != null)
            {
                int enumInt = Convert.ToInt32(EnumIn_RT.GetValue(executor).ToEnum().Item2);
                IntegerOut_RT.SourceValue.SetInteger(enumInt);
            }
            else
            {
                IntegerOut_RT.SourceValue.Reset();
            }
            return IntegerOut_RT.SourceValue;
        }
    }
}